import axios from 'axios'
import qs from 'qs'
import store from '../store/store'
import config from './config-client'


axios.interceptors.response.use(response => response, error => Promise.resolve(error.response))


export default {
  post(url, data) {
    return axios({
      method: 'post',
      url: url,
      data: qs.stringify(data),
      timeout: config.timeout,
      headers: {
        'X-Requested-With': 'XMLHttpRequest',
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
      }
    }).then((response)=>{
      return response.data
    })
  },
  get(url, params) {
    return axios({
      method: 'get',
      url: url,
      params,
      timeout: config.timeout,
      headers: {
        'X-Requested-With': 'XMLHttpRequest'
      }
    }).then((response)=>{
      return response.data
    })
  }
}
